Back to course home
0% completed
Vote For New Content
Microsoft Hard Problems
Regular Expression Matching (hard)
Solution: Regular Expression Matching
First Missing Positive (hard)
Solution: First Missing Positive
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Sliding Window Maximum (hard)
Solution: Sliding Window Maximum
Count Unique Characters of All Substrings of a Given String (hard)
Solution: Count Unique Characters of All Substrings of a Given String
Word Ladder (hard)
Solution: Word Ladder
Word Ladder II (hard)
Solution: Word Ladder II
Number of Flowers in Full Bloom (hard)
Solution: Number of Flowers in Full Bloom
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Combinations (medium)
Problem Statement
Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n].
Each combination must be a unique set of numbers, order of which does not matter.
Examples
-
Example 1:
- Input:
n = 3, k = 2 - Expected Output:
[[1, 2], [1, 3], [2, 3]] - Justification:
[[1, 2], [1, 3], [2, 3]]are all combinations of size 2, which we can create using[1, 2, 3].
- Input:
-
Example 2:
- Input:
n = 4, k = 1 - Expected Output:
[[1], [2], [3], [4]] - Justification:
[[1], [2], [3], [4]]are all combinations of size 1, which we can create using `[1, 2, 3, 4].
- Input:
-
Example 3:
- Input:
n = 5, k = 3 - Expected Output:
[[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3, 5], [1, 4, 5], [2, 3, 4], [2, 3, 5], [2, 4, 5], [3, 4, 5]] - Justification: We unique triplets using numbers 1 to 5, yielding ten different combinations.
- Input:
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Rotate Image
Solution: Combinations
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself